﻿using System;
using System.Windows.Data;

namespace Dsl.Ped.Common.Converters
{
    /// <summary>
    /// Convert given object into its <see cref="Type"/> name
    /// </summary>
    public class ObjectToTypeCheckConverter : IValueConverter
    {
        #region Implementation of IValueConverter

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null) return false;
            if (parameter == null) return false;
            if (!(parameter is Type)) return false;

            var requiredType = parameter as Type;
            var currentType = value.GetType();

            if (requiredType.IsAssignableFrom(currentType)) return true;

            return false;
        }

        public object ConvertBack(object value, Type targetType,object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
